﻿using CQRSFramework.Domains.Impl;
using CQRSFramework.Test.events;

namespace CQRSFramework.Test.domain
{
    public class AccountAggregate : AggregateRoot
    {
        public string UserId { get; set; }
        public string Name { get; set; }
        public AccountAggregate(string id, string userId, string name) : base(id)
        {
            ApplyChange(new AccountCreatedEvent(userId, name));
        }
        public void ChangeName(string name, string userId)
        {
            ApplyChange(new AccountNameChangedEvent(name, userId));
        }

        public void Handle(AccountCreatedEvent evnt)
        {
            UserId = evnt.UserId;
            Name = evnt.Name;
        }

        public void Handle(AccountNameChangedEvent envt)
        {
            Name = envt.Name;
        }

    }
}
